#ifndef MESSAGERECEIVER_H_
#define MESSAGERECEIVER_H_

#include "NetworkEvent.h"
#include "NetworkWrapper.h"
#include "Thread.h"

class MessageReceiver : public Thread
{
public:
    MessageReceiver(const TCPsocket& socket);
    virtual ~MessageReceiver();

    void send(void* data, size_t size);

protected:
    virtual void mainLoop();
    virtual void cleanUp();

    virtual void* createDisconnectEvent(NetworkEvent::Header& header) = 0;
    virtual void pushEvent(NetworkEvent::Header& header, void* data) = 0;
    TCPsocket socket;

private:
    NetworkEvent::Header fetchHeader();
    void* fetchData(NetworkEvent::Header& header);
};

#endif
